using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;

public class UI_InGame_教程 : MonoBehaviour
{
	public Image _Img_对话框;

	public Text _Text_说话的人Name;

	public Text _Text_对话文本;

	public CanvasGroup _CG;

	public List<Sprite> _List_对话框头像;

	public C_对话Item_Data _对话_场景1教程;

	public C_对话Item_Data _对话_定身术教程;

	public float _打字间隔 = 0.2f;

	private bool _CanNext;

	private void Start()
	{
		_CanNext = false;
		_CG.alpha = 0f;
		_CG.blocksRaycasts = false;
		base.gameObject.SetActive(value: false);
	}

	private void Update()
	{
		if (Input.anyKeyDown)
		{
			_CanNext = true;
		}
	}

	public void F_开始教程(Enum_教程类型 教程类型)
	{
		if (_对话_场景1教程._教程类型 == 教程类型)
		{
			F_开始对话(_对话_场景1教程);
		}
		else if (_对话_定身术教程._教程类型 == 教程类型)
		{
			F_开始对话(_对话_定身术教程);
		}
	}

	public void F_开始对话(C_对话Item_Data 对话Data)
	{
		base.gameObject.SetActive(value: true);
		_CG.alpha = 1f;
		_CG.blocksRaycasts = true;
		StartCoroutine(Cor_对话(对话Data));
	}

	private IEnumerator Cor_对话(C_对话Item_Data 对话Data)
	{
		Time.timeScale = 0f;
		GameManager._CanPlay = false;
		foreach (C_对话Item_Data_内容 item in 对话Data._List_对话内容)
		{
			_Img_对话框.sprite = _List_对话框头像[Mathf.Clamp((int)item._ID, 0, _List_对话框头像.Count)];
			_Text_说话的人Name.text = item._ID.ToString() + ":";
			string 最终文本 = item._Text;
			WaitForSecondsRealtime wfsr = new WaitForSecondsRealtime(_打字间隔);
			for (int i = 0; i < 最终文本.Length; i++)
			{
				string text = 最终文本.Substring(0, i);
				_Text_对话文本.text = text;
				if (_CanNext)
				{
					_CanNext = false;
					break;
				}
				yield return wfsr;
			}
			_Text_对话文本.text = 最终文本;
			while (!_CanNext)
			{
				yield return wfsr;
			}
			_CanNext = false;
		}
		if (对话Data._教程类型 == Enum_教程类型.定身术教程)
		{
			MonoSingleton<GameManager>.Instance.F_解锁定身术();
		}
		Time.timeScale = 1f;
		GameManager._CanPlay = true;
		yield return null;
		_CG.alpha = 0f;
		_CG.blocksRaycasts = false;
		base.gameObject.SetActive(value: false);
	}
}
